package com.huike.web.controller.clues;


import com.github.pagehelper.PageInfo;
import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.clues.service.TbActivityService;
import com.huike.common.constant.HttpStatus;
import com.huike.common.constant.ScheduleConstants;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 活动管理
 */
@Slf4j
@RestController
@RequestMapping("/clues/activity")
@Api(tags = "活动管理相关接口操作")
public class TbActivityController extends BaseController {

    @Resource
    private TbActivityService tbActivityService;

    /**
     * 获取所有的活动信息（分页）[这个有问题]
     */
    @ApiOperation("获取所有的活动信息（分页）接口")
    @GetMapping("/list")
    public TableDataInfo list(TbActivity tbActivity) {
        log.info("获取所有的活动信息（分页）:{}", tbActivity);
        startPage();
        List<TbActivity> list = tbActivityService.selectActivityList(tbActivity);
        Integer count = tbActivityService.selectStatus("2");
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        Map<String, Object> params = new HashMap<>();
        params.put("total", new PageInfo(list).getTotal());
        params.put("pass", count);
        params.put("reject", 0);
        params.put("toAudit", 0);
        params.put("finish", 0);
        rspData.setParams(params);
        return rspData;
    }
    /**
     * 通过Id删除活力信息
     */
    @ApiOperation("通过Id删除活力信息接口")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteByIds(@PathVariable List<Integer> ids) {
        log.info("通过Id删除活力信息接口：{}", ids);
        tbActivityService.deleteByIds(ids);
        return new AjaxResult(200, "删除成功");
    }

    /**
     * 通过id查询活动信息
     */
    @ApiOperation("通过id查询活动信息接口")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable Long id) {
        log.info("通过id查询活动信息接口：{}", id);
        TbActivity tbActivity = tbActivityService.selectById(id);
        return AjaxResult.success("操作成功", tbActivity);
    }

    /**
     * 修改活动信息
     */
    @ApiOperation("修改活动信息接口")
    @PutMapping
    private AjaxResult updateActivity(@RequestBody TbActivity tbActivity) {
        log.info("修改活动信息接口:{}", tbActivity);
        tbActivityService.updateActivity(tbActivity);
        return new AjaxResult(200, "更新成功");

    }

    /**
     * 添加活动信息
     */
    @ApiOperation("添加活动信息接口")
    @PostMapping
    private AjaxResult insertTbActivity(@RequestBody TbActivity tbActivity) {
        log.info("添加活动信息接口:{}", tbActivity);

        tbActivityService.insertTbActivity(tbActivity);
        return new AjaxResult(200, "操作成功");
    }


}
